package com.example.newbee.mvp.view;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.mylibrary.mvp.view.BaseActivity;
import com.example.newbee.MainActivity;
import com.example.newbee.R;
import com.example.newbee.mvp.contact.RegisterContact;
import com.example.newbee.mvp.model.RegisterModel;
import com.example.newbee.mvp.presenter.RegisterPresenter;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class LoginActivity extends BaseActivity<RegisterPresenter> implements RegisterContact.View {
    RegisterPresenter registerPresenter;
    @BindView(R.id.act_login_back_iv)
    ImageView backId;
    @BindView(R.id.act_login_username_et)
    EditText userId;
    @BindView(R.id.act_login_pwd_et)
    EditText pwdId;
    @BindView(R.id.act_login_btn)
    Button loginId;
    @BindView(R.id.act_login_go_reg_tv)
    TextView registerId;

    @Override
    public int bondLayout() {
        return R.layout.activity_login;
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {
        registerPresenter=new RegisterPresenter(new RegisterModel(),this);
    }

    @Override
    public void loadLayout() {

    }

    @Override
    public void hideLayout() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        Intent intent = getIntent();
        String user = intent.getStringExtra("user");
        String pwd = intent.getStringExtra("pwd");
        if(user!=null && pwd !=null){
            userId.setText(user);
            pwdId.setText(pwd);
        }
    }


    @Override
    public String getUsername() {
        return userId.getText().toString().trim();
    }

    @Override
    public String getPwd() {
        return pwdId.getText().toString().trim();
    }

    @Override
    public void goLogin() {

    }

    @Override
    public void goMain() {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
    }
    @OnClick({R.id.act_login_back_iv, R.id.act_login_btn, R.id.act_login_go_reg_tv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.act_login_back_iv:
                Intent intent = new Intent(this,RegisterActivity.class);
                startActivity(intent);
                break;
            case R.id.act_login_btn:
                registerPresenter.login();
                break;
            case R.id.act_login_go_reg_tv:
                Intent intent1 = new Intent(this,RegisterActivity.class);
                startActivity(intent1);
                break;
        }
    }

}
